package com.service;

import static com.def.GenericDef.RETURN_CODE_UNKNOWN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.dao.IHisRetPrdInfoDao;
import com.icim.service.ICIMBaseService;
import com.mapKeyVal.key.PrdEvtcateKey;
import com.model.his.His_ret_prd_info;
import com.tx.Hpinqbox.HpinqboxI;
import com.tx.Hpinqbox.HpinqboxO;
import com.tx.Hpinqbox.HpinqboxO1;
import com.util.MqOpe;
import com.util.Util;

@Scope("prototype")
@Service("HpinqboxService")
public class HpinqboxService extends ICIMBaseService{
	private Logger logger = Logger.getLogger(HpinqboxService.class);
	private HpinqboxI inTrx;
	private HpinqboxO outTrx;

	@Autowired
	private IHisRetPrdInfoDao hisRetPrdInfoDao;

	public String subMainProc(String strInMsg) {
		MqOpe mqOpe = new MqOpe();
		inTrx = new HpinqboxI();
		outTrx = new HpinqboxO();

		inTrx = (HpinqboxI) mqOpe.inStr2Obj(strInMsg, inTrx);
		try {
			char action_flg = inTrx.getAction_flg().charAt(0);
			switch (action_flg) {
			case 'Q':
				queryMainProc();
				break;
			default:
				logger.error("mapping no action_flg ,error");
			}

		} catch (Exception e) {
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			outTrx.setRtn_mesg(Util.stackTraceToString(e));
		}

		return mqOpe.obj2Str(outTrx);
	}

	private void queryMainProc() {
		queryHoldBox();
		queryExchangeBox();
		queryScrpBox();
		queryChangeWhouseBox();

	}

	private void queryHoldBox() {
		String sql = "FROM His_ret_prd_info WHERE evt_cate IN('WIPR','WIPC','HLDC','HLDR') ORDER BY prd_seq_id,sta_time_d";
		List<His_ret_prd_info> hisRetPrdInfoList = hisRetPrdInfoDao.find(sql);
		Map<PrdEvtcateKey, His_ret_prd_info> holdMap = new HashMap<PrdEvtcateKey, His_ret_prd_info>();
		List<HpinqboxO1> oary1List = new ArrayList<HpinqboxO1>();

		for (His_ret_prd_info hisRetPrdInfo : hisRetPrdInfoList) {
			holdMap.put(new PrdEvtcateKey(hisRetPrdInfo.getPrd_seq_id(), hisRetPrdInfo.getEvt_cate()), hisRetPrdInfo);
		}
		
		Iterator<Entry<PrdEvtcateKey,His_ret_prd_info>> it = holdMap.entrySet().iterator();
		while(it.hasNext()){
			
		}
	}

	private void queryExchangeBox() {

	}

	private void queryScrpBox() {

	}

	private void queryChangeWhouseBox() {

	}

}
